// import { Indicator } from 'mint-ui';
import store from "@/store/index";
import axios from "axios";
import router from "@/router";
export default {
  common: {
    method: "GET",
    data: {},
    params: {},
    headers: {},
  },

  $axios(options = {}) {
    options.method = options.method || this.common.method;
    options.data = options.data || this.common.data;
    options.params = options.params || this.common.params;
    options.headers = options.headers || this.common.headers;

    //请求前=> 显示加载中
    // Indicator.open('加载中...');
    console.log(
      "在request中获取store.state.user.token",
      store.state.user.token     //null
    );
    //判断有没有传入token
    if (options.headers.token) {
      //判断有没有token的值 ==》 有没有登录
      if (!options.headers.token) {
        return router.push("/login");
      }
      options.headers.token = store.state.user.token
    }

    return axios(options).then((v) => {
      let data = v.data.data;
      return new Promise((res, rej) => {
        if (!v) return rej();
        //结束==> 关闭加载中
        setTimeout(() => {
          // Indicator.close();
        }, 500);
        res(data);
      });
    });
  },
};
